﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using UMLObjects;

using System.Globalization;


namespace WIN_UML_Editor
{
    /// <summary>
    /// Interaction logic for Activity.xaml
    /// </summary>
    public partial class UCInitialState : UserControl, IDragableUC, IArrowedUC, IUMLUC
    {
        private InitialState state = new InitialState();
        private List<UCArrow> arrowsToThis = new List<UCArrow>();

        public List<UCArrow> ArrowsToThis
        {
            get { return arrowsToThis; }
        }

        private List<UCArrow> arrowsFromThis = new List<UCArrow>();
        public List<UCArrow> ArrowsFromThis
        {
            get { return arrowsFromThis; }
        }


        public UCInitialState(InitialState _state)
        {
            InitializeComponent();
            mainGrid.DataContext = state = _state; //Use initial state data...
            fill.Fill = getColor();
        }

        public IUMLObject getObject()
        {
            return state;
        }

        public string ObjName
        {
            get { return state.Name; }
            set { state.Name = value; }
        }

        public Point ObjPosition
        {
            get { return state.Position; }
            set { state.Position = value; }
        }

        public Point ObjPrePosition
        {
            get { return state.PrePosition; }
            set { state.PrePosition = value; }
        }

        public void UpdateArrows()
        {
            foreach (UCArrow arrow in arrowsFromThis)
            {
                arrow.Update();
            }
        }

        public void AddArrowFrom(UCArrow arrow)
        {
            if (arrowsFromThis.Count == 0)  //Kun hvis der ikke er en pil allerede
                arrowsFromThis.Add(arrow);
        }

        public void AddArrowTo(UCArrow arrow)
        {
            //Nothing since no arrows to this object can be made
        }

        public void RemoveArrowFrom(UCArrow arrow)
        {
            if (arrowsFromThis.Contains(arrow))
                arrowsFromThis.Remove(arrow);
        }

        public void RemoveArrowTo(UCArrow arrow)
        {
            //Nothing since no arrows to this object can be made
        }

        public Boolean canReceiveArrow()
        {
            return false; //Can never have arrows point on this object
        }


        public Boolean canSendArrow()
        {
            //Can only have 1 arrow
            if (arrowsFromThis.Count == 0)
                return true;
            else
                return false;
        }

        //Colour when not selected
        public LinearGradientBrush getColor()
        {
            LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush();
            myLinearGradientBrush.StartPoint = new Point(1, 0);
            myLinearGradientBrush.EndPoint = new Point(0, 1);
            myLinearGradientBrush.GradientStops.Add(
                new GradientStop(Colors.DarkRed, 1.0));
            myLinearGradientBrush.GradientStops.Add(
                new GradientStop(Colors.LavenderBlush, 0.1));
            return myLinearGradientBrush;
        }

        //Colour when selected
        public LinearGradientBrush getColorSelect()
        {
            LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush();
            myLinearGradientBrush.StartPoint = new Point(1, 0);
            myLinearGradientBrush.EndPoint = new Point(0, 1);
            myLinearGradientBrush.GradientStops.Add(
                new GradientStop(Colors.IndianRed, 1.0));
            myLinearGradientBrush.GradientStops.Add(
                new GradientStop(Colors.Khaki, 0.1));
            return myLinearGradientBrush;

        }

        public void select()
        {
            fill.Fill = getColorSelect();
        }

        public void deselect()
        {
            fill.Fill = getColor();
        }
    }

}
